package com.itheima.day09_IO;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class InputStreamTest{
  public static void main(String[] args){
    	read1();
    	System.out.println("======");
      read2();
  }
  
  public static void read1(){
    //TODO 一次读取一个字节
      try (FileInputStream fis = new FileInputStream("E:\\file01.txt")){
          int byt ;
          while((byt = fis.read()) != -1){
              System.out.print((char)byt);
          }
      }catch (Exception e){
          e.printStackTrace();
      }
  }
  public static void read2(){
    //TODO 一次读取多个字节
      try(FileInputStream fis = new FileInputStream("E:\\file01.txt")){
          int len;
          byte[] bytes = new byte[1024];
          while((len = fis.read(bytes))!= -1){
              System.out.println(new String(bytes,0,len));
          }

      } catch (FileNotFoundException e) {
          throw new RuntimeException(e);
      } catch (IOException e) {
          throw new RuntimeException(e);
      }
  }
}